<?php
use yii\helpers\Url;
/* @var $this \yii\web\View */
/* @var $content string */
/* @var \common\models\UserConsignee $info */

$this->title = '个人病史'
?>
<section class="app-container app-form app-send">
    
    <!-- form -->
    <div class="app-form-group">
        <label for="">受托关系：</label>
        <input type="text" class="app-form-control" placeholder="受托关系" name="relation" value="<?= $info->relation ?>">
    </div>
    <div class="app-form-group">
        <label for="">姓名：</label>
        <input type="text" class="app-form-control" placeholder="姓名" name="realname" value="<?= $info->realname ?>">
    </div>
    <div class="app-form-group">
        <label for="">手机号码：</label>
        <input type="text" class="app-form-control" placeholder="手机号码" name="mobile" value="<?= $info->mobile ?>">
    </div>
    
    <div class="app-form-group">
        <label for="">性别:</label>
        <select name="sex" id="sex" class="app-form-control">
            <option value="1" <?php if($info->sex == 1) { echo 'selected'; } ?>>男</option>
            <option value="2" <?php if($info->sex == 2) { echo 'selected'; } ?>>女</option>
        </select>
    </div>
    
    <div class="app-form-group">
        <label for="">身份证号：</label>
        <input type="text" class="app-form-control" placeholder="身份证号" name="idcard" value="<?= $info->idcard ?>" >
    </div>
    <div class="app-form-group">
        <label for="">微信号码：</label>
        <input type="text" class="app-form-control" placeholder="微信号码" name="wechat_name" value="<?= $info->wechat_name ?>" >
    </div>

    <div class="app-form-group">
        <label for="">邮箱：</label>
        <input type="text" class="app-form-control" name="email" placeholder="邮箱" value="<?= $info->email ?>">
    </div>

    <div class="app-form-group">
        <label for="">住址：</label>
        <input type="text" class="app-form-control" name="address" placeholder="住址" value="<?= $info->address ?>">
    </div>
    
    
    <div class="app-form-button">
        <input type="hidden" name="_csrf-frontend" value="<?= Yii::$app->request->csrfToken ?>">
        <button class="app-form-control app-btn-submit" id="submit">保存</button>
    </div>
    
</section>
<script src="/js/jquery.min.js"></script>
<script src="/js/layer_mobile/layer.js"></script>
<script>
    $(function(){
        var _csrf = '<?= Yii::$app->request->csrfToken ?>';
        var submitUrl = '<?= Url::toRoute(['member/consignee']) ?>'
        $('#submit').click(function(){
            var relation = $('input[name="relation"]').val();
            var sex = $("#sex").val();
            var mobile = $("input[name='mobile']").val();
            var realname = $("input[name='realname']").val();
            var idcard = $("input[name='idcard']").val();
            var wechat_name = $("input[name='wechat_name']").val();
            var email = $('input[name="email"]').val();
            var address = $("input[name='address']").val();
            var request = {
                relation: relation,realname:realname,mobile:mobile,sex:sex,idcard:idcard,wechat_name:wechat_name,email:email,address:address,"_csrf-frontend":_csrf
            }
            layer.open({type: 2, shadeClose: false});
            $.post(submitUrl, request, function(result){
                layer.closeAll();
                if( result.success == true ){
                    layer.open({
                        shadeClose: false,
                        content: '保存成功',
                        btn: '确定',
                        end: function(){
                            window.history.back();
                        }
                    });
                }else{
                    layer.open({
                        shadeClose: false,
                        content: result.msg,
                        btn: '确定',
                    });
                }
            }, 'json')
            
        })
    });
</script>
